<?php
/* 
    Project     : 48c6c450f1a4a0cc53d9585dc0fee742
    Created on  : Mar 16, 2013, 11:29:15 PM
    Author      : Truong Khuong - khuongxuantruong@gmail.com
    Description :
        Purpose of the stylesheet follows.
*/
class news_model extends CI_Model {

    function __construct($type=null,$init=false)
    {
        parent::__construct();
        $this->cate_type=$type;
		$this->HieCats=array();
		if($init)$this->HierarchicalCats(0);
		
    }
    function get($news_id){
        $query=$this->db
                ->where("news_id",$news_id)
                ->or_where("news_alias",$news_id)
                ->get("news");
        return $query->row();
    }
    function get_by_alias_type($news_alias,$type=null){
        if($type!=null)$this->db->where('cate_type',$type);
        $query=$this->db
                ->from('news')
                ->join('categories','cate_id=news_category')
                ->where(array(
                    "news_alias"=>$news_alias,
                    'news_status'=>'true'
                    ))
                ->get();
        return $query->row();
    }
    function get_in_cate_ids($cate_ids=null){
        if($cate_ids!=null){
            if(!is_array($cate_ids))$cate_ids=array($cate_ids);
            $this->db->where_in('news_category',$cate_ids);
        }
        $query=$this->db
                ->where('news_status','true')
                ->order_by('news_insert','DESC')
                ->get("news"); 
        return $query->result();
    }
    function get_in_cate_aliass($cate_aliass=null){
        if($cate_aliass!=null){
            if(!is_array($cate_aliass))$cate_aliass=array($cate_aliass);
            $this->db->where_in('cate_alias',$cate_aliass);
        }
        $query=$this->db
                ->from('news')
                ->join('categories','cate_id=news_category')
                ->where('news_status','true')
                ->order_by('news_insert','DESC')
                ->get(); 
        return $query->result();
    }
    function get_in_cate_aliass_by_type($cate_aliass=null,$type=null){
        if($cate_aliass!=null){
            if(!is_array($cate_aliass))$cate_aliass=array($cate_aliass);
            $this->db->where_in('cate_alias',$cate_aliass);
        }
        if($type!=null)$this->db->where('cate_type',$type);
        $query=$this->db
                ->from('news')
                ->join('categories','cate_id=news_category')
                ->where('news_status','true')
                ->order_by('news_insert','DESC')
                ->get(); 
        return $query->result();
    }
    function get_by_cate_type($type=null){
        if($type!=null)$this->db->where('cate_type',$type);
        $query=$this->db
                ->from('news')
                ->join('categories','cate_id=news_category')
                ->where('news_status','true')
                ->order_by('news_insert','DESC')
                ->get(); 
        return $query->result();
    }
    
}
?>
